define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'enterprise/enterprise/index' + location.search,
                    add_url: 'enterprise/enterprise/add',
                    edit_url: 'enterprise/enterprise/edit',
                    del_url: 'enterprise/enterprise/del',
                    multi_url: 'enterprise/enterprise/multi',
                    import_url: 'enterprise/enterprise/import',
                    table: 'enterprise',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'enterprise_id',
                sortName: 'enterprise_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'enterprise_id', title: __('Enterprise_id')},
                        {
                            field: 'enterprise_name',
                            title: __('Enterprise_name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {field: 'province', title: __('Province')},
                        {field: 'city', title: __('City')},
                        {field: 'district', title: __('District')},
                        {
                            field: 'address',
                            title: __('Address'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {field: 'business_license', title: __('Business_license'), operate: 'LIKE'},
                        {
                            field: 'business_license_image',
                            title: __('Business_license_image'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        {field: 'legal_name', title: __('Legal_name'), operate: 'LIKE'},
                        {
                            field: 'business_type', title: __('Business_type'), formatter: function (row) {
                                if (row.business_type == 1) {
                                    return '餐饮';
                                }
                                return '食品';
                            }
                        },
                        {field: 'employee_mobile', title: __('Employee_mobile')},
                        {
                            field: 'food_security_license',
                            title: __('Food_security_license'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
